import 'package:flutter/material.dart';

class MyCheckBox extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => MyCheckBoxState();
}

class MyCheckBoxState extends State {
  bool flag = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text('MyCheckBox')),
        body: Column(
            mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Row(mainAxisAlignment: MainAxisAlignment.center, children: [
              Checkbox(
                activeColor: Colors.green,
                value: this.flag,
                onChanged: (value) {
                  this.setState(() {
                    this.flag = value;
                  });
                },
              ),
              Text(this.flag ? '选中' : '未选中'),
            ]),
            SizedBox(height: 20),
            CheckboxListTile(
              title: Text('CheckboxListTile'),
              subtitle: Text('CheckboxListTile'),
              secondary: Icon(Icons.home),
              value: this.flag,
              onChanged: (value) {
                this.setState(() {
                  this.flag = value;
                });
              },
            )
          ],
        ));
  }
}
